#include "communicationproxy.h"

CommunicationProxy::CommunicationProxy(QObject *parent)
    : QObject(parent)
    , m_obj(nullptr)
{

}

void CommunicationProxy::setCommunication(Communication *obj)
{
    if (!obj) {
        return;
    }

    m_obj = obj;
}

Communication *CommunicationProxy::communication() const
{
    return m_obj;
}

bool CommunicationProxy::isValid() const
{
    Q_ASSERT(m_obj);
    bool ret = false;
    QMetaObject::invokeMethod(m_obj, "isValid", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, ret));
    return ret;
}

void CommunicationProxy::connectToHost(const QString &portName)
{
    Q_ASSERT(m_obj);
    QMetaObject::invokeMethod(m_obj, "connectToHost", Qt::BlockingQueuedConnection, Q_ARG(QString, portName));
}

void CommunicationProxy::disconnectFromHost()
{
    Q_ASSERT(m_obj);
    QMetaObject::invokeMethod(m_obj, "disconnectFromHost", Qt::BlockingQueuedConnection);
}
